package net.jumpengine.event;

import java.awt.Point;

import javafx.scene.image.Image;
import javafx.scene.input.MouseButton;
import javafx.scene.paint.Color;
import net.jumpengine.M;
import net.jumpengine.Manager;
import net.jumpengine.bean.BoxBase;
import net.jumpengine.bean.ImageBase;
import net.jumpengine.bean.TextBase;
import net.jumpengine.bean.TextRect;
import net.jumpengine.inter.IAction;
import net.jumpengine.inter.IHandle;
import net.jumpengine.inter.IStateEvent;
import net.jumpengine.po.Border;
import net.jumpengine.ui.ButtonBase;
import net.jumpengine.util.UDraw;

public class ConfirmStateEvent implements IStateEvent{
	private ImageBase back;
	private boolean load=false;
	
	private TextRect title;
	private TextBase text;
	
	private String titleStr,textStr;
	private IHandle handle;

	@Override
	public void setBackImage(Image image) {
		if(back==null) {
			back=new ImageBase(0,0,M.w(),M.h(),-1,image);
			M.b().add(back);
		}else {
			back.setImage(image);
		}
	}

	@Override
	public boolean isLoaded() {
		return load;
	}

	@Override
	public void load() {
		Point center = UDraw.center(360, 200);
		
		title =new TextRect(center.x, center.y, 360, 30, "");
		title.setBackColor(Color.web("#990000"));
		title.setColor(Color.web("#eeeeee"));
		title.setFont(UDraw.getFont("黑体", 18, true, false));
		M.b().add(title);
		
		BoxBase box=new BoxBase(center.x, center.y+30, 360, 170, new Border(), Color.WHITE);
		M.b().add(box);
		
		TextBase question=new TextBase(center.x+40, center.y+40, "?");
		question.setColor(Color.YELLOW);
		question.setFont(UDraw.getFont("黑体", 100, true, false));
		M.b().add(question);
		
		text=new TextBase(center.x+140, center.y+40,200,"");
		text.setFont(UDraw.getFont(18));
		M.b().add(text);
		
		Border b=new Border(1, 1, 1, 1, 6);
		
		ButtonBase btu=new ButtonBase(center.x+70, center.y+155, 100, 30, b, "确  定");
		btu.setFont(UDraw.getFont(13));
		btu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Object target) {
				if(ConfirmStateEvent.this.handle!=null) {
					ConfirmStateEvent.this.handle.handle(target,null);		
				}
			}
		});
		M.b().add(btu);
		
		btu=new ButtonBase(center.x+200, center.y+155, 100, 30, b, "取  消");
		btu.setFont(UDraw.getFont(13));
		btu.setAction(new IAction() {
			@Override
			public void handle(int x, int y, MouseButton button, Object target) {
				Manager.beforeState();
			}
		});
		M.b().add(btu);
		
		load=true;
	}

	@Override
	public void show() {
		title.setText(titleStr);
		text.setText(textStr);
	}

	@Override
	public void pause() { }

	@Override
	public void end() { }
	
	public void set(String title,String text,IHandle handle) {
		titleStr=title;
		textStr=text;
		this.handle=handle;
	}
	
}
